package com.wanshi.po;

import com.wanshi.utils.Constants;

import java.util.List;

public class Page<T> {


    private List<T> list;

    private int curpage;

    private int count;


    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public int getFirst() {
        return 1;
    }

    public int getLast() {
        return count% Constants.PAGE_SIZE == 0?count/Constants.PAGE_SIZE:count/Constants.PAGE_SIZE+1;
    }

    public int getShang() {
        return curpage==1?curpage:curpage-1;
    }


    public int getNext() {
        return curpage == getLast() ? curpage:curpage+1;
    }

    public int getCurpage() {
        return curpage;
    }

    public void setCurpage(int curpage) {
        this.curpage = curpage;
    }


    public int[] getStartAndEnd(){
        int[] arr = new int[2];
        int length = 9;
        if(getLast() < length){
            arr[0] = 1;
            arr[1] = getLast();
        }else{
            if(curpage < length/2){
                arr[0] = 1;
                arr[1] = length;
            }else if(curpage > getLast()-length/2){
                arr[0] = getLast()-length+1;
                arr[1] = getLast();
            }else{
                arr[0] = curpage - 4;
                arr[1] = curpage + 4;
            }
        }
        return arr;
    }
}
